package sugarbind_input

class Area {

    String area_Name
	String area_Ref
	Area  area_Parent
	String area_Notes
	
    static constraints = {
		area_Name(blank:false)
		area_Ref(nullable:true)
		area_Parent(nullable:true)
		area_Notes(nullable:true)
		organism(nullable:true)
		
		
		area_Name(unique:['area_Type'])
	}
	
	static hasOne = [area_Type:Area_Type, organism:Organism]

	static hasMany = [disease_Area_Agents:Disease_Area_Agent]
	static belongsTo = [Ligand]
	
	
	static mapping = {
//		id column: 'area_id'
		id generator: 'sequence', params: [sequence: 'area_id_seq']

		//ligands joinTable: [name: "ligand_area", key: 'area_id' ]
	}
	
	public String toString(){
		def area = ""
		if(area_Type != null)
		{
			area += area_Type.area_Type_Name + " : "
		}
		area += area_Name + " (" + id +")"  //+ " " +area_Type + " " + host.host_Name
		
		if(organism != null)
		{
			area += " / " + organism.toString()
		}
		
		return area
	}
	
	public static listAreas()
	{
		Area.list().sort{ it.toString(); }
	}
}
